/**
 * Created by Administrator on 2017/4/20.
 */



var Poker = require('./Poker');

var BASE = 10;

var ColorCompareValue = {}
ColorCompareValue[Poker.Color.DIAMOND] = 1;
ColorCompareValue[Poker.Color.CLUB] = 2;
ColorCompareValue[Poker.Color.HEART] = 3;
ColorCompareValue[Poker.Color.SPADE] = 4;

function getPoint(card) {
    var point = Poker.getPoint(card);
    if (point > BASE) {
        point = BASE;
    }
    return point;
}

function calcNiuCards(cardsArr) {
    var results = [];
    var len = cardsArr.length;
    for (var c1 = 0; c1 < len - 2; ++c1) {
        for (var c2 = c1 + 1; c2 < len - 1; ++c2) {
            for (var c3 = c2 + 1; c3 < len; ++c3) {
                var point = getPoint(cardsArr[c1]) + getPoint(cardsArr[c2]) + getPoint(cardsArr[c3]);
                if (point%BASE == 0) {
                    results.push([cardsArr[c1], cardsArr[c2], cardsArr[c3]]);
                }
            }
        }
    }
    return results;
}

function cardLT(card1, card2) {
    var point1 = Poker.getPoint(card1);
    var point2 = Poker.getPoint(card2);

    if (point1 == point2) {
        var color1 = Poker.getColor(card1);
        var color2 = Poker.getColor(card2);
        return ColorCompareValue[color1] > ColorCompareValue[color2];
    } else {
        return point1 > point2;
    }
}

module.exports = {
    BASE: BASE,
    ColorCompareValue: ColorCompareValue,
    getPoint: getPoint,
    calcNiuCards: calcNiuCards,
    cardLT: cardLT,
}